:focus {
  outline: none;
}

::-moz-focus-inner {
  border: 0;
}

textarea,
input[type="text"],
input[type="email"],
input[type="number"],
input[type="email"],
input[type="date"],
input[type="file"],
select {
  padding: 10px 14px;
  background: rgba(128, 128, 128, 0.05);
  color: colour('white');
  font-family: $font-family-alt;
  font-size: 14px;
  border-radius: 3px;
  letter-spacing: -0.01rem;
  border: 2px solid rgba(128, 128, 128, 0.35);

  &:focus,
  &:active {
    border-color: colour('blue');
  }

  &:disabled {
    opacity: 0.5;
  }

  &.tiny {
    width: 50px;
    padding-left: 4px;
    padding-right: 4px;
    text-align: center;
  }

  @include theme('light') {
    color: colour('darkest_grey');
    background: rgba(255, 255, 255, 0.75);
  }

  &::placeholder {
    color: rgba(128, 128, 128, 0.6);
  }

  &:-ms-input-placeholder {
    color: rgba(128, 128, 128, 0.6);
  }

  &::-ms-input-placeholder {
    color: rgba(128, 128, 128, 0.6);
  }
}

input[type="number"] {
  -moz-appearance: textfield;

  &::-webkit-inner-spin-button,
  &::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
}

input[type="radio"] {
  & + .label:before {
    content: " ";
    display: inline-block;
    width: 1.8rem;
    height: 1.8rem;
    border-radius: 50%;
    background: transparent;
    margin-right: 0.5rem;
    border: 2px solid rgba(128, 128, 128, 0.35);
    box-sizing: border-box;
    background: rgba(128, 128, 128, 0.05);

    @include theme('light') {
      background: colour('white');
    }
  }

  &:checked + .label:after {
    content: " ";
    display: inline-block;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    position: absolute;
    left: 0.55rem;
    background: colour('white');
  }

  &:focus + .label:before,
  &:active + .label:before {
    background: rgba(128, 128, 128, 1);
  }

  @include theme('light') {
    &:checked + .label:after {
      background: colour('darkest_grey');
    }
  }
}

input[type="checkbox"] {
  & + .label:before {
    font-family: "Material Icons";
    font-size: 1.2rem;
    line-height: 1.6rem;
    content: "";
    color: colour('white');
    display: inline-flex;
    padding: 0 0.2rem;
    height: calc(1.6rem - 2px);
    width: calc(1.2rem - 2px);
    text-align: center;
    border-radius: 3px;
    border: 2px solid rgba(128, 128, 128, 0.35);
    margin-right: 0.5rem;
    background: rgba(128, 128, 128, 0.05);

    @include theme('light') {
      background: colour('white');
    }
  }

  &:checked + .label:before {
    content: "\e5ca";
  }

  &:focus + .label:before,
  &:active + .label:before {
    background: colour('mid_grey');
  }

  @include theme('light') {
    & + .label:before {
      color: colour('darkest_grey');
    }
  }
}

select {
  max-width: 100%;
  -webkit-appearance: none;

  option {
    background: colour('white');
    color: colour('darkest_grey');
    max-width: 100%;
    box-sizing: border-box;
  }
}

.button-wrapper {
  padding: 10px 0;
  margin-top: -1px;

  &.large {
    padding: 16px 0;
  }
}

.text-button {
  cursor: pointer;

  &.destructive {
    color: colour('red');
  }
}

.action {
  @include click_feedback();
  cursor: pointer;
}

.button {
  @include animate();
  @include feature_font();
  @include noselect();
  display: inline-flex;
  font-size: 14px;
  color: inherit;
  background: transparent;
  padding: 9px 40px 7px;
  margin: 5px 20px 5px 0;
  box-sizing: border-box;
  border-radius: 100px;
  vertical-align: middle;
  position: relative;
  cursor: pointer;
  letter-spacing: -0.01rem;
  text-align: center;
  text-decoration: none;
  border: 2px solid transparent;

  @include theme('dark') {
    color: colour('white');
  }

  .icon {
    padding-right: 8px;
    margin: 0;
  }

  &:active {
    @include noanimate();
    transform: translate(1px, 1px);
  }

  &:hover {
    text-decoration: none;
  }

  @include theme('light') {
    &--default {
      border-color: colour('darkest_grey');

      &:active {
        background: rgba(128, 128, 128, 0.2);
      }

      &:hover {
        box-shadow: 0 0 10px rgba(colour('darkest_grey'), 0.3);
      }
    }
  }

  @include theme('dark') {
    &--default {
      border-color: colour('white');

      &:active {
        background: rgba(128, 128, 128, 0.2);
      }

      &:hover {
        box-shadow: 0 0 10px rgba(colour('white'), 0.5);
      }
    }
  }

  &--small {
    padding: 6px 18px 4px;
  }

  &--tiny {
    padding: 3px 10px 2px;
    margin: 0;
  }

  &--large {
    padding: 16px 50px 14px;
  }

  &--icon {
    padding: 0.2rem !important;
    font-size: 1.4rem;
    border: none;
    box-shadow: none !important;

    &:hover {
      color: colour('blue');
    }

    .icon {
      padding: 0 !important;
    }
  }

  &--pull-right {
    margin-right: 0;
    margin-left: 30px;
  }

  &--primary {
    background: colour('turquoise');
    border-color: colour('turquoise');
    color: colour('white');

    &:active {
      background: darken(colour('turquoise'), 10%);
      border-color: darken(colour('turquoise'), 10%);
    }

    &:hover {
      box-shadow: 0 0 10px rgba(colour('turquoise'), 0.5);
    }
  }

  &--darken {
    border-color: rgba(0, 0, 0, 0.8);

    &:hover {
      box-shadow: 0 0 10px rgba(colour('black'), 0.3);
    }
  }

  &--lighten {
    border-color: rgba(255, 255, 255, 0.8);

    &:hover {
      box-shadow: 0 0 10px rgba(colour('white'), 0.3);
    }
  }

  &--secondary {
    background: colour('blue');
    color: colour('white');

    &:active {
      background: darken(colour('blue'), 10%);
    }

    &:hover {
      box-shadow: 0 0 10px rgba(colour('blue'), 0.5);
    }
  }

  &--white {
    background: colour('white');
    color: colour('black');

    &:active {
      background: rgba(128, 128, 128, 0.2);
    }

    &:hover {
      box-shadow: 0 0 10px rgba(colour('white'), 0.5);
    }
  }

  &--grey {
    border-color: colour('grey');

    &:hover {
      box-shadow: 0 0 10px rgba(colour('grey'), 0.5);
    }
  }

  &--black {
    border-color: colour('darkest_grey');

    &:hover {
      box-shadow: 0 0 10px rgba(colour('darkest_grey'), 0.3);
    }
  }

  &--confirming,
  &--destructive {
    border-color: colour('red');
    color: colour('red');

    &:active {
      background: rgba(128, 128, 128, 0.2);
    }

    &:hover,
    &-hover:hover {
      color: colour('red');
      box-shadow: 0 0 10px rgba(colour('red'), 0.5);
    }
  }

  &--timing-out {
    position: relative;
    overflow: hidden;

    &:before {
      @include animate_timeout(2s);
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      width: 0;
      background: colour('middle_grey');
      opacity: 0.25;
    }
  }

  &--discrete {
    border: none;
    box-shadow: none !important;

    &:before {
      display: none;
    }
  }

  &--working {
    position: relative;
    cursor: wait !important;
    color: rgba(0,0,0,0) !important;

    &:before {
      pointer-events: none;
      display: inline-block;
      content: "";
      animation: spin 1s infinite linear;
      width: 1.2em;
      height: 1.2em;
      border-radius: 100px;
      position: absolute;
      left: 50%;
      margin-left: -0.6em;
      border: 2px solid transparent;
      border-top-color: colour('middle_grey');
      border-right-color: colour('middle_grey');
      z-index: 1;
      box-sizing: border-box;
    }
  }

  &--disabled,
  &[disabled],
  &[disabled="disabled"] {
    opacity: 0.5;
    cursor: not-allowed !important;
    color: colour('mid_grey');
    border-color: colour('mid_grey');
    background: transparent;
  }

  @include responsive($bp_medium) {
    padding-left: 28px;
    padding-right: 28px;

    &--large {
      width: 100%;
      display: block;
      margin-bottom: 10px;
    }
  }

  @include responsive($bp_narrow) {
    padding-left: 20px;
    padding-right: 20px;
    font-size: 12px;
    margin: 2px 10px 2px 0;

    &--large {
      width: 100%;
      display: block;
      margin-bottom: 10px;
    }
  }
}

.field {
  @include clearfix();
  @include noselect();
  display: flex;
  padding-bottom: 12px;

  & > .name {
    display: block;
    padding-top: 10px;
    width: 20%;

    .icon {
      font-size: 0.9em;
      margin-bottom: 0.3em;
    }
  }

  & > .input {
    width: 80%;

    input,
    select,
    textarea {
      width: 100%;
    }

    .text {
      display: block;
      padding: 10px 14px 10px 0;
    }

    .icon {
      margin-bottom: -3px;
    }
  }

  &--condensed {
    display: block;

    & > .name {
      width: auto;
    }

    & > .input {
      width: auto;
    }
  }

  .label {
    .tooltip {
      left: -4px;
    }
  }

  &.sub-field {
    padding: 0;
  }

  &.button-wrapper {
    .button {
      margin-bottom: 0;
    }
  }

  .description {
    display: block;
    padding: 6px 0 4px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);

    &.error {
      color: colour('red');
      display: inline-block;
      opacity: 1;
    }

    a {
      color: inherit;
    }
  }

  &.radio,
  &.checkbox {
    input[type="radio"],
    input[type="checkbox"] {
      display: none;
    }

    .input {
      label {
        display: inline-block;
        padding: 0.25rem 0;

        input:disabled + .label {
          opacity: 0.5;
          cursor: not-allowed;
        }

        &:not(:last-child) {
          padding-right: 1rem;
        }
      }
    }

    .label {
      display: inline-flex;
      float: none;
      width: auto;
      position: relative;
      cursor: pointer;
      align-items: center;
      vertical-align: middle;
    }

    &--block {
      .label,
      label {
        display: block;
      }
    }
  }

  &.range {
    position: relative;

    .input-range {
      height: auto;
    }

    .label {
      padding-bottom: 6px;
    }

    .input-range__track,
    .input-range__slider-container {
      transition: none;
      height: 6px;
      border-radius: 3px;
      cursor: col-resize;
    }

    .input-range__track--background {
      margin: 0;
      background: rgba(100, 100, 100, 0.5);
    }

    .input-range__track--active {
      background: colour('blue');
    }

    .input-range__slider-container {
      .input-range__slider {
        cursor: col-resize;
        background: colour('blue');
        border: none;
        top: 0;
        height: 6px;
        width: 20px;
        margin: -6px 0 0 0;
        border-radius: 3px 0 0 3px;
      }

      &:last-child {
        .input-range__slider {
          border-radius: 0 3px 3px 0;
          margin-left: -12px;
        }
      }
    }
  }

  @include theme('light') {
    .description {
      color: rgba(0, 0, 0, 0.6);
    }
  }
}

.text-field {
  &__wrapper {
    position: relative;
  }

  &__saved {
    @include fadeout($delay: 1s);
    position: absolute;
    top: calc(50% - 0.5em);
    right: 10px;
    line-height: 1em;
    font-size: 0.8rem;
    text-transform: uppercase;
    font-weight: bold;
    color: colour('green');
  }
}

@include responsive($bp_medium) {
  .field {
    display: block;

    .name {
      width: auto;
      padding: 0 0 4px 0;
    }

    .input {
      width: auto;

      .text {
        padding: 0 20px 0 0;
      }
    }
  }
}
